package com.fengzhilian.timewheel.wheel;

import com.fengzhilian.timewheel.container.Bucket;
import com.fengzhilian.timewheel.container.DelayQueue;

/**
 * 时轮
 * @author 郭智峰
 * @Date 2019年12月25日
 */
public class HourTimeWheel extends TimeWheel {
    @Override
    public TimeWheel getOverflowWheel() {
        if (overflowWheel == null) {
            synchronized (this) {
                if (overflowWheel == null) {
                    overflowWheel = new DayTimeWheel(currentTimestamp,timeWheelType,delayQueue);
                }
            }
        }
        return overflowWheel;
    }
    public HourTimeWheel(long currentTimestamp, String timeWheelType, DelayQueue delayQueue){
        this.interval=60*60*1000;
        this.tickMs=60*1000;
        this.wheelSize=60;
        this.timeWheelType=timeWheelType;
        this.buckets = new Bucket[wheelSize];
        for (int i = 0; i < wheelSize; i++) {
            buckets[i] = new Bucket();
            this.delayQueue=delayQueue;
            this.delayQueue.addBucket(buckets[i]);
        }

        this.currentTimestamp = currentTimestamp;
    }
}
